import 'package:flutter/material.dart';
import 'package:flutter_base_widget/file_manager/file_util.dart';

class FileOperations extends StatefulWidget {
  @override
  _FileOperationsState createState() => _FileOperationsState();
}

class _FileOperationsState extends State<FileOperations> {

  var fileContnet = "no data";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("文件操作"),
        leading: IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: (){
            Navigator.of(context).pop();
          },
        ),
      ),
      body: Column(
        children: <Widget>[
          RaisedButton(
            child: Text("保存文件"),
            onPressed: () async {
             var file = await FileUtils.saveToFile("测试数据");
             print("保存文件 ${file.path}");
            },
          ),
          RaisedButton(
            child: Text("读取文件"),
            onPressed: (){
              FileUtils.readFromFile().then((res){
                setState(() {
                  fileContnet = res ?? "没有读到数据";
                });
              });
            },
          ),
          Text(fileContnet)
        ],
      ),
    );
  }
}